{% extends 'base.html' %}

{% block load_css %}
    <link href="/static/css/plugins/sweetalert/sweetalert.css" rel="stylesheet">
{% endblock %}

{% block mbx %}
    <div class="row wrapper border-bottom white-bg page-heading">
        <div class="col-sm-4">
            <h2>更新机房</h2>
            <ol class="breadcrumb">
                <li>
                    <a href="{% url 'index' %}">首页</a>
                </li>
                <li>
                    <a href="">资产管理</a>
                </li>
                <li>
                    <a href="">更新机房</a>
                </li>
            </ol>
        </div>
    </div>
{% endblock %}

{% block body %}
    <div class="ibox-content">
        <form id="submit_form" class="form-horizontal">
            {% csrf_token %}
            <div class="form-group"><label class="col-sm-2 control-label">机房简称</label>
                <div class="col-sm-6"><input type="text" class="form-control" name="name" value="{{ idc_obj.name }}"></div>
            </div>
            <div class="hr-line-dashed"></div>
            <div class="form-group"><label class="col-sm-2 control-label">机房名称</label>
                <div class="col-sm-6"><input type="text" class="form-control" name="name_cn" value="{{ idc_obj.name_cn }}"></div>
            </div>
            <div class="hr-line-dashed"></div>
            <div class="form-group"><label class="col-sm-2 control-label">机房地址</label>
                <div class="col-sm-6"><input type="text" class="form-control" name="address" value="{{ idc_obj.address }}"></div>
            </div>
            <div class="hr-line-dashed"></div>
            <div class="form-group"><label class="col-sm-2 control-label">机房座机电话</label>
                <div class="col-sm-6"><input type="text" class="form-control" name="phone" value="{{ idc_obj.phone }}"></div>
            </div>
            <div class="hr-line-dashed"></div>
            <div class="form-group"><label class="col-sm-2 control-label">机房负责人姓名</label>
                <div class="col-sm-6"><input type="text" class="form-control" name="username" value="{{ idc_obj.username }}"></div>
            </div>
            <div class="hr-line-dashed"></div>
            <div class="form-group"><label class="col-sm-2 control-label">机房负责人邮箱</label>
                <div class="col-sm-6"><input type="email" class="form-control" name="user_email" value="{{ idc_obj.user_email }}"></div>
            </div>
            <div class="form-group"><label class="col-sm-2 control-label">机房负责人手机号</label>
                <div class="col-sm-6"><input type="text" class="form-control" name="user_phone" value="{{ idc_obj.user_phone }}"></div>
            </div>
            <div class="hr-line-dashed"></div>
            <div class="form-group">
                <div class="col-sm-4 col-sm-offset-2">
                    <input type="hidden" value="{{ idc_obj.id }}" name="id">
                    <button class="btn btn-white" type="submit">取消</button>
                    <button class="btn btn-primary" type="submit">保存更改</button>
                </div>
            </div>
        </form>
    </div>
{% endblock %}

{% block load_js %}
    <script src="/static/js/plugins/validate/jquery.validate.js"></script>
    <script src="/static/js/plugins/validate/messages_zh.js"></script>
    <script src="/static/js/plugins/sweetalert/sweetalert.min.js"></script>
    <script>
        $(document).ready(function () {
            $("#submit_form").validate({
                rules: {
                    name: {
                        required: true
                    },
                    username: {
                        required: true
                    },
                    name_cn: {
                        required: true
                    },
                    address: {
                        required: true
                    },
                    username_email: {
                        required: true
                    },
                    username_phone: {
                        required: true
                    },
                    phone: {
                        required: true
                    }
                }, submitHandler: function () {
                    var str = $('#submit_form').serialize();
                    $.post('{% url 'idc_update' %}', str, function (res) {
                        if (res.status == 0) {
                            swal({
                                title: res.msg,
                                type: 'success',
                                confirmButtonText: "OK"
                            }, function () {
                                window.location.href = '{% url 'idc_list' %}';
                            });
                        } else {
                            swal({
                                title: res.msg,
                                type: 'error',
                                confirmButtonText: "知道了"
                            });
                        }
                    });
                }
            });
        });
    </script>
{% endblock %}